<include file="public@header"/>
</head>
<style>
    /*td input, td select {*/
    /*    width: auto;*/
    /*    max-width: 180px;*/
    /*}*/

    .form-horizontal .control-group1 {
        float: left;
        width: 15%;
        margin-bottom: 20px;
    }

    .form-horizontal .control-label {
        width: 80px;
    }

    .form-horizontal .controls {
        margin-left: 90px;
    }

    input, select, textarea, .uneditable-input {
        max-width: 580px;
        width: 100px;
        min-width: auto;
    }

    .div_service {
        width: 200px;
        height: 100px;
        border: #dedcdc solid 1px;
        border-radius: 5px;
        float: left;
        margin-right: 20px;
    }

    .div_service_text {
        background-color: #1C9846;
        color: white;
        width: 80px;
        height: 25px;
        line-height: 25px;
        padding-left: 10px;
        margin: 10px 0 0 10px;
    }

    #table1 table tr th, #table1 table tr td {
        height: 30px;
        line-height: 30px;
        border: #DDDDDD solid 1px;
        /*color: white;*/
        /*padding: 0 40px 20px 10px;*/
    }

    .div_service_sum {
        margin: 20px 0 0 60px;

    }

    /*table tr th {*/
    /*    height: 30px;*/
    /*    color: white;*/
    /*    padding: 0 60px 0 10px;*/
    /*}*/

    table tr th {
        height: 30px;
        /*color: white;*/
        padding: 0 60px 0 10px;
        text-align: center;
    }

    /*table thead tr {*/
    /*    background: #0B90C4;*/
    /*}*/
    #table1 tr td {
        /*max-width: 80px;*/
        width: auto;
        text-align: center;
    }

    .dis {
        display: none
    }

    .dis2 {

    }

    /*.content_nav .check_info{flex:1; display:flex;flex-direction: column;align-items: center;justify-content: center;}*/


</style>
<body>
<div class="wrap js-check-wrap">
    <div class="well form-search">
        <label style="margin-right: 30px">
            请选择业务类型:
            <select id="itype" class="form-control" onchange="changItype()" style="width: 200px"
                    value="{:input('request.itype/s','')}">
                <option value="">-请选择-</option>
                <option value="6">碑文收入</option>
                <option value="9">前台商品收入</option>
                <option value="3" selected>落葬收入</option>
                <option value="8">迁墓收入</option>
                <option value="7">业务工本费收入</option>
                <option value="11">换碑收入</option>
                <option value="2">常规维保收入</option>
                <option value="12">石材维保收入</option>
                <option value="4">维护费收入</option>
            </select>
        </label>
        <label>
            <div id="jingbanrenId" class="dis2"></div>
        </label>
        <label>
            <div id="xiadanrenId" class="dis"></div>
        </label>
        </br>
        起止时间: <input type="text" class='js-date form-control' id="start_time" name="start_time"
                     value="{:input('request.start_time/s','')}" placeholder="请输入开始时间">
        ~
        <input type="text" class='js-date form-control' id="end_time" name="end_time"
               value="{:input('request.end_time/s','')}"
               placeholder="请输入结束时间" style="margin-right: 30px">
        <button class="btn btn-default" name="type" value="1" onclick="typeClick(1)">昨日</button>
        <button class="btn btn-default" name="type" value="2" onclick="typeClick(2)">今日</button>
        <button class="btn btn-default" name="type" value="3" onclick="typeClick(3)">上月</button>
        <button class="btn btn-default" name="type" value="4" onclick="typeClick(4)">本月</button>
        <button class="btn btn-default" name="type" value="5" onclick="typeClick(5)">上一年</button>
        <button class="btn btn-default" name="type" value="6" style="margin-right: 30px" onclick="typeClick(6)">本年
        </button>
        <input type="hidden" id="type">
        <input type="submit" id="submit" class="btn btn-primary" value="查询"/>
        <input type="button" id="reset" class="btn btn-primary" value="重置"/>
    </div>
    <div style="width: 1000px;" id="statistics">

    </div>
    <div style="margin-top: 145px" id="table1">
        <div class="control-group1-p div_content">
            <!---tab页-->
            <ul class="nav_tabs" style="margin: 0; padding-top: 9px !important;height: 38px !important;">
                <li class="active" data-t="1"><a href="javascript:">客户统计</a></li>
                <!--                                <li  data-t="2"><a href="javascript:">收款历史</a></li>-->
            </ul>
            <div class="control-group1-p nav_content">
                <div class="content_nav">
                    <div style="border: 1px solid #0b81c4;border-top: 0;">
                        <div class="fixed-table-body">
                            <div class="fixed-table-loading" style="top: 41px; display: none;">数据正在加载中...</div>
                            <table id="table_1" class="table table-hover   table-striped">
                                <thead>
                                <tr>

                                    <th style="" data-field="no">
                                        <div class="th-inner ">序号</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th style="" data-field="type">
                                        <div class="th-inner ">类型</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th style="" data-field="pay_sn">
                                        <div class="th-inner ">付款日期</div>
                                        <div class="fht-cell"></div>
                                    </th>

                                    <th class="" id="goumuren" data-field="total_price">
                                        <div class="th-inner ">购墓人</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th class="" id="quyu" style="">
                                        <div class="th-inner ">区域</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th class="" id="weizhi" data-field="real_name">
                                        <div class="th-inner ">具体位置</div>
                                        <div class="fht-cell"></div>
                                    </th>

                                    <th class="" id="num" data-field="tomb_num">
                                        <div class="th-inner ">墓位编号</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th class="" id="zhixingbumen">
                                        <div class="th-inner ">执行部门</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th style="">
                                        <div class="th-inner ">收款人</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th class="" id="jingban">
                                        <div class="th-inner ">经办人</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th class="dis" id="xiadan">
                                        <div class="th-inner ">下单人</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                    <th style="text-align: center; " class="" id="status" data-field="operate">
                                        <div>状态</div>
                                        <div class="fht-cell"></div>
                                    </th>
                                </tr>
                                </thead>
                                <tbody id="table">


                                </tbody>
                            </table>
                            <!--分页-->
                            <nav aria-label="Page navigation">
                                <ul class="pagination" id="page"></ul>
                            </nav>

                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>


</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<link href="__STATIC__/js/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
<script src="__STATIC__/js/bootstrap-table/dist/bootstrap-table.js"></script>
<script src="__STATIC__/js/bootstrap-table/dist/locale/bootstrap-table-zh-CN.js"></script>
<!--<script type="text/javascript" src="__STATIC__/js/layer/layer.js"></script>-->
<!--<script type="text/javascript" src="__STATIC__/js/init_base.js?v={:time()}"></script>-->

<script>
    // 全局变量
    var itype = 3;
    var jingBanRen = "";
    var xiaDanRen = "";
    var pages = 1;
    var lastPage = 0;

    /**
     * 选择经办人
     * */
    function changeJingBanRen() {
        jingBanRen = $("#jingbanren").val();
    }

    /**
     * 选择下单人*/
    function changeXiaDanRen() {
        xiaDanRen = $("#xiadanren").val();
    }

    /**
     *  选择业务类型
     *  */
    function changItype(val) {
        itype = $("#itype").val()
        console.log(itype)
        if (itype == 9) {
            $("#xiadanrenId").attr("class", "dis2")
            $("#jingbanrenId").attr("class", "dis")
            $("#jingbanren").val("");
            jingBanRen = "";
        } else {
            $("#xiadanrenId").attr("class", "dis")
            $("#jingbanrenId").attr("class", "dis2")
            $("#xiadanren").val("");
            xiaDanRen = "";
        }

    }

    // 点击指定日期按钮
    function typeClick(type) {
        console.log(type);
        $("#start_time").val("");
        $("#end_time").val("");
        $("#type").val(type);
        findAll();
    }

    // 点击页码
    function page(val) {
        console.log(val);
        pages = val;
        findAll();
    }

    /**
     * 点击下一页
     * @returns {boolean}
     */
    function nextPage() {
        if (pages === lastPage) {
            return false;
        }
        pages = pages + 1;
        findAll();
        console.log(pages + 1)
    }

    function isNull(data) {
        return data == null ? '' : data;
    }

    /**
     * 点击上一页
     * @returns {boolean}
     */
    function previousPage() {
        if (pages === 1) {
            return false;
        }
        pages = pages - 1;
        findAll();
        console.log(pages - 1);
    }

    /**
     * 查询列表
     */
    function findAll() {
        var param = {
            type: $("#type").val(),
            itype: itype,
            start_time: $("#start_time").val(),
            end_time: $("#end_time").val(),
            jingBanRen: jingBanRen,
            xiaDanRen: xiaDanRen,
            page: pages

        };
        console.log(param)
        $.ajax({
            url: "{:url('Analysis/inComeIndex')}",
            type: "post",
            data: param,
            dataType: "json",
            success: function (data) {
                console.log(data)
                var jingBanRenHtml = "按经办人检索：<select class=\"form-control\" id='jingbanren' onchange='changeJingBanRen()' style=\"width: 200px\"><option value=''>-请选择-</option>"
                for (var i = 0; i < data.data.jingBanRenData.length; i++) {
                    if (jingBanRen == data.data.jingBanRenData[i].id) {
                        jingBanRenHtml += "<option selected value=" + data.data.jingBanRenData[i].id + ">" + data.data.jingBanRenData[i].user_nickname + "</option>"
                    } else {
                        jingBanRenHtml += "<option value=" + data.data.jingBanRenData[i].id + ">" + data.data.jingBanRenData[i].user_nickname + "</option>"
                    }
                }
                jingBanRenHtml += "</select>";
                var xiaDanRenHtml = "按下单人检索：<select class=\"form-control\" id='xiadanren' onchange='changeXiaDanRen()' style=\"width: 200px;\"><option value=''>-请选择-</option>"
                for (var i = 0; i < data.data.xiaDanRenData.length; i++) {
                    if (xiaDanRen == data.data.xiaDanRenData[i].id) {
                        xiaDanRenHtml += "<option selected value=" + data.data.xiaDanRenData[i].id + ">" + data.data.xiaDanRenData[i].user_nickname + "</option>"
                    } else {
                        xiaDanRenHtml += "<option value=" + data.data.xiaDanRenData[i].id + ">" + data.data.xiaDanRenData[i].user_nickname + "</option>"
                    }
                }
                xiaDanRenHtml += "</select>";

                var statistics = "";
                statistics += "<div class=\"div_service\"><p class=\"div_service_text\">业务累计</p>\n" +
                    "            <p class=\"div_service_sum\"><b>" + data.data.dataCount + "单</b></p></div>"
                statistics += "<div class=\"div_service\"><p class=\"div_service_text\">收入累计</p>\n" +
                    "            <p class=\"div_service_sum\"><b>" + data.data.sum.flowingSum + "元</b></p></div>"
                statistics += "<div class=\"div_service\"><p class=\"div_service_text\">优惠累计</p>\n" +
                    "            <p class=\"div_service_sum\"><b>" + data.data.sum.discount + "元</b></p></div>"
                statistics += "<div class=\"div_service\"><p class=\"div_service_text\">实收累计</p>\n" +
                    "            <p class=\"div_service_sum\"><b>" + data.data.sum.dealSum + "元</b></p></div>"
                var tableHtml = "";
                var tableData = data.data.data.data;
                var a = 0;

                for (var k = 0; k < tableData.length; k++) {
                    a++;
                    var type = tableData[k].itype == 3 ? '落葬业务' : (tableData[k].itype == 4 ? '维护费' : (tableData[k].itype == 7 ? '证件工本费' : (tableData[k].itype == 9 ? '单独买商品' : tableData[k].itype == 6 ? '碑文收入' : (tableData[k].itype == 2 ? '常规维保收入' : (tableData[k].itype == 11 ? '换碑收入' : (tableData[k].itype == 8 ? '迁墓业务' : (tableData[k].itype == 12 ? '石材维保收入' : '')))))))
                    tableHtml += "<tr><td>" + a + "</td>" +
                        "<td>" + type + "</td>" +
                        "<td>" + tableData[k].add_time + "</td>";
                    ;
                    if (tableData[k].itype != 9) {
                        tableHtml += "<td>" + tableData[k].buyer_name + "</td>" +
                            "<td>" + tableData[k].tomb_region + "</td>" +
                            "<td>" + isNull(tableData[k].tomb_address) + "</td>" +
                            "<td>" + isNull(tableData[k].tomb_num) + "</td>";
                    }
                    if (tableData[k].itype == 3 || tableData[k].itype == 8 || tableData[k].itype == 2 || tableData[k].itype == 12) {
                        tableHtml += "<td>" + isNull(tableData[k].department_name) + "</td>";
                    }

                    tableHtml += "<td>" + isNull(tableData[k].shoukuanren) + "</td>" +
                        "<td>" + isNull(tableData[k].user_nickname) + "</td>";
                    // "<td>" + tableData[k].department_name + "</td>";
                    if (tableData[k].itype == 3 || tableData[k].itype == 8 || tableData[k].itype == 2 || tableData[k].itype == 12) {
                        var type = tableData[k].sbStatus == 1 ? '未确认' : (tableData[k].sbStatus == 2 ? '已确认' : (tableData[k].sbStatus == 3 ? '已完成' : ''))
                        tableHtml += "<td>" + isNull(type) + "</td>";
                    }
                    if (tableData[k].itype == 4) {
                        tableHtml += "<td>已缴纳</td>";
                    }
                }
                $("#table").html(tableHtml);
                lastPage = data.data.data.last_page;
                var page = "<li>\n" +
                    "                                        <a onclick='previousPage()' aria-label=\"Previous\">\n" +
                    "                                            <span aria-hidden=\"true\">&laquo;</span>\n" +
                    "                                        </a>\n" +
                    "                                    </li>";
                for (var p = 1; p < lastPage + 1; p++) {
                    page += "<li><a  onclick='page(" + p + ")'>" + p + "</a></li>"
                }
                page += "<li>\n" +
                    "                                        <a  onclick='nextPage()' aria-label=\"Next\">\n" +
                    "                                            <span aria-hidden=\"true\">&raquo;</span>\n" +
                    "                                        </a>\n" +
                    "                                    </li>";
                $("#page").html(page);
                $("#jingbanrenId").html(jingBanRenHtml);
                $("#xiadanrenId").html(xiaDanRenHtml);
                $("#statistics").html(statistics);
            }, error: function (data) {
                console.log(data)
                console.log("失败")
            }
        })
    }

    $(document).ready(function () {
        findAll();
        // 查询
        $("#submit").click(function () {
            pages = 1
            $("#type").val("")
            console.log(111)
            if (itype == 9) {
                $("#goumuren").attr("class", "dis");
                $("#weizhi").attr("class", "dis");
                $("#quyu").attr("class", "dis");
                $("#zhixingbumen").attr("class", "dis");
                $("#num").attr("class", "dis");
                $("#jingban").attr("class", "dis");
                $("#xiadan").attr("class", "");
                $("#status").attr("class", "dis");
            } else if (itype == 3 || itype == 8 || itype == 2 || itype == 12) {
                $("#goumuren").attr("class", "");
                $("#weizhi").attr("class", "");
                $("#quyu").attr("class", "");
                $("#zhixingbumen").attr("class", "");
                $("#num").attr("class", "");
                $("#jingban").attr("class", "");
                $("#xiadan").attr("class", "dis");
                $("#status").attr("class", "");
            } else if (itype == 4) {
                $("#goumuren").attr("class", "");
                $("#weizhi").attr("class", "");
                $("#quyu").attr("class", "");
                $("#num").attr("class", "");
                $("#jingban").attr("class", "");
                $("#status").attr("class", "");
                $("#zhixingbumen").attr("class", "dis");
            }
            else {
                $("#goumuren").attr("class", "");
                $("#weizhi").attr("class", "");
                $("#quyu").attr("class", "");
                $("#zhixingbumen").attr("class", "dis");
                $("#num").attr("class", "");
                $("#jingban").attr("class", "");
                $("#xiadan").attr("class", "dis");
                $("#status").attr("class", "dis");
            }

            findAll();
        });
        // 重置条件
        $("#reset").click(function () {
            $("#jingbanren").val("");
            $("#xiadanren").val("");
            $("#type").val("");
            $("#start_time").val("");
            $("#end_time").val("");
            $("#itype").val("3");
            $("#xiadanrenId").attr("class", "dis")
            $("#jingbanrenId").attr("class", "dis2")
            pages = 1;
            jingBanRen = "";
            xiaDanRen = "";
            itype = 3;
            findAll();
        })

    })
</script>
</body>

</html>